package io.kiki.task.server.job.task.support.stop;

import io.kiki.task.common.core.enums.JobTaskTypeEnum;
import io.kiki.task.server.job.task.support.JobTaskStopHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public final class JobTaskStopFactory {

    private static final ConcurrentHashMap<JobTaskTypeEnum, JobTaskStopHandler> CACHE = new ConcurrentHashMap<>();

    private JobTaskStopFactory() {
    }

    public static void registerTaskStop(JobTaskTypeEnum taskInstanceType, JobTaskStopHandler interrupt) {
        CACHE.put(taskInstanceType, interrupt);
    }

    public static JobTaskStopHandler getJobTaskStop(Integer type) {
        return CACHE.get(JobTaskTypeEnum.valueOf(type.toString()));
    }

    public static JobTaskStopFactory createJobTaskStopFactory() {
        return new JobTaskStopFactory();
    }
}
